Digital Galton Board VGA Simulation
A real-time statistical physics simulation built on the Raspberry Pi Pico (RP2040) demonstrating the Central Limit Theorem in action.
Contributors: Tony Kariuki and Jeremy Simon
System Architecture
This system merges real-time graphics, hardware-accelerated audio, and concurrent protothreads to simulate up to 700 bouncing balls simultaneously at a stable 30 frames-per-second.
- Microcontroller: RP2040 (Raspberry Pi Pico) utilizing fixed-point arithmetic to avoid floating-point overhead.
- Visuals: Custom VGA rendering driver outputting a real-time histogram and live physics.
- Audio: Direct Memory Access (DMA) triggered sound effects driving an SPI-connected Digital-to-Analog Converter (DAC) at ~44kHz.
- Concurrency: Three discrete protothreads handling VGA/Physics, state machine user inputs, and switch debouncing.
Statistics and Mathematics
The Galton Board is a classic demonstration of the Central Limit Theorem. As balls fall, they have a 50% probability of bouncing left or right at each peg. Each row acts as an independent Bernoulli trial.
For a board with 16 rows, the binomial distribution is:
As the number of rows () increases, the discrete binomial distribution smoothly converges into a continuous Gaussian normal curve (). The expected mean () and standard deviation () for our 16-row setup are calculated as follows:
Mean
Standard Deviation

Goal for final simulation. Provided by Hunter Adams and Bruce Land
// Fixed-Point Physics Structs
typedef struct {
fix15 x;
fix15 y;
fix15 vx;
fix15 vy;
int last_peg;
} Ball;
// State Machine Debouncing
case MAYBE_PRESSED:
if (keypress == possible_press && keypress == 0) {
switch (button_state) {
case RESET:
reset_histogram();
button_state = ADJUST_BALLS;
break;
// State transitions...
}
debounce_state = PRESSED;
}
User Control
A hardware potentiometer mapped to the ADC allows real-time tuning of simulation parameters.